home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor2 / pres.doc < prev    next >
Text File  |  1995-03-31  |  4KB  |  106 lines

  1. LONG REALS MEET RESISTANCE  by Joe Horn 
  2. ========================== 
  3.  
  4. This should prove to you that you need the power of System RPL! 
  5.  
  6. Jason L Braddy (jlbraddy@IASTATE.EDU) asked for a program to calculate 
  7. parallel resistance, and Joel Kolstad (kolstad@cae.wisc.edu) wrote: 
  8.  
  9. > This is what I just came up with on the spur of the moment: 
  10. >  \<<0 3 DEPTH START SWAP INV + NEXT INV \>> 
  11. > Someone else might have something better if they thought about it a 
  12. > little.  Personally, I'd use a list of resistances and just 
  13. > change the DEPTH to an OBJ->. 
  14.  
  15. Although mathematically flawless, there is a problem with this solution. 
  16. All those INVs can easily accumulate roundoff error. For example, an 
  17. input of 10 and 15 should yield 6, but instead it gives 5.99999999999. 
  18. You might say that this is not enough of an error to worry about. But 
  19. there's an easy way to guarantee perfect accuracy. 
  20.  
  21. If you only have two values to calculate, then the formula 1/(1/a+1/b) 
  22. should not be used; instead, use ab/(a+b) which is more accurate because 
  23. it has only a single division in it. A simple program for that is: 
  24.  
  25. %%HP:T(3); 
  26. \<< * LASTARG + / \>> 
  27.  
  28. INPUT: Two reals.  OUTPUT: real. 
  29. EXAMPLE: 10 15 -> 6. 
  30.  
  31. If you have more than two resistors, the roundoff error can get really 
  32. bad. My favorite examples violate the associative property of addition: 
  33. if you enter 153, 238 and 252 into Joel's program, it gives one answer; 
  34. enter them in reverse order, and you get another answer! And worst of all, 
  35. both answers are wrong!  This is not a unique case; there are infinitely 
  36. many. And the more terms you have, the worse the error can get. 
  37.  
  38. One solution is to take the more accurate formula above and generalize it 
  39. for any number of values. For example, for three values (a, b, c), we get 
  40. abc/(ab+ac+bc); for four, we get abcd/(abc+abd+acd+bcd), and so on. 
  41. A simple program for this method is: 
  42.  
  43. %%HP:T(3); 
  44. \<< OBJ\-> OBJ\-> - 1 DUP ROT 
  45.   START 3 PICK * OVER + ROT ROT * SWAP 
  46.   NEXT / 
  47. \>> 
  48.  
  49. INPUT: Array of reals.  OUTPUT: real. 
  50. EXAMPLE: [ 153 238 252 ]  -->  68. 
  51.  
  52. But even this method occasionally gets roundoff errors due to the 12-digit 
  53. limit of the HP 48. 
  54.  
  55. The solution, of course, is to use Long Reals during the calculation and 
  56. only round the final result. PRES is a System RPL program to do that. It 
  57. takes an array as its input, as suggested by Joel. It also uses the sign 
  58. to assist problem solving. Like the financial software that uses the sign 
  59. to differentiate between cash flow in and cash flow out, I'll use the sign 
  60. here to differentiate between the resistance of an individual resistor and 
  61. the total resistance of the circuit. 
  62.  
  63. INPUT: Array of Reals (positive = individual resistor, 
  64.                        negative = total resistance) 
  65. OUTPUT: Real (positive/negative = as above) 
  66.  
  67. System RPL listing produced by Brian Maguire's SRPL library: 
  68.  
  69. %%HP:; 
  70. @ PRES by Joe Horn. Decode with SRPL-> 
  71. ":: CK1&Dispatch # 4h 
  72.   :: %% 0 SWAP 
  73. (37BCB) INDEX@ 
  74. (3558E) %>%% %%1/ ROT 
  75. %%+ SWAP LOOP DROP 
  76. %%1/ %%>% %CHS 
  77.   ; 
  78. ;" 
  79.  
  80. Note: The (37BCB) and (3558E) above are in-line five-nibble addresses 
  81. (unsupported and unnamed entry points); this is how Maguire's library 
  82. decompiles them. They are NOT comments. If using Detlef Mueller's 
  83. RPL.LIB to compile it, change (37BCB) to PTR 37BCB, etc. 
  84.  
  85. EXAMPLE 1: What is the total resistance of a circuit of three resistors in 
  86. parallel, with individual values of 120, 144, and 180 ohms? 
  87.  
  88.     SOLUTION: Type [ 120 144 180 ] and press PRES. See -48; the circuit 
  89.     has a total resistance of 48 ohms. 
  90.  
  91. EXAMPLE 2: If you have two resistors in parallel, each 120 ohms, and you 
  92. want to add a third one in parallel with them such that the total 
  93. resistance becomes 44 ohms, what value resistor must you use? 
  94.  
  95.     SOLUTION: Type [ 120 120 -44 ] and press PRES. See 165; the third 
  96.     resistor must have a value of 165 ohms. 
  97.  
  98. EXAMPLE 3:  Bill can paint a house in 6 hours; Ted can do it in 10 hours. 
  99. When they work together with Alice, they finish in 3 hours. How long would 
  100. it take Alice by herself? 
  101.  
  102.     SOLUTION: Type [ 6 10 -3 ] and press PRES. See 15; it would take 
  103.     Alice 15 hours to paint the house by herself. 
  104.  
  105. -Joseph K. Horn-   EQU   akcs.joehorn@hpcvbbs.cv.hp.com 
  106.